package pkg

import (
	"context"
	"github.com/qiniu/go-sdk/v7/storagev2/credentials"
	"github.com/qiniu/go-sdk/v7/storagev2/http_client"
	"github.com/qiniu/go-sdk/v7/storagev2/uploader"
	"golang.org/x/mod/modfile"
	"net/http"
)

func Upload(file http.File, syntax modfile.FileSyntax) (string, error) {
	accessKey := ""
	secretKey := ""
	mac := credentials.NewCredentials(accessKey, secretKey)
	bucket := "2305as"
	key := syntax.Name
	uploadManager := uploader.NewUploadManager(&uploader.UploadManagerOptions{
		Options: http_client.Options{
			Credentials: mac,
		},
	})
	err := uploadManager.UploadReader(context.Background(), file, &uploader.ObjectOptions{
		BucketName: bucket,
		ObjectName: &key,
		CustomVars: map[string]string{
			"name": "github logo",
		},
		FileName: "",
	}, nil)
	return "", err
}
